# 元组（tuple）就是不能修改元素的列表，用小括号表示
t1 = (1, "feng", True)
print(f"tuple1 is {t1}, tuple1 's type is{type(t1)}")

t2 = ("feng")
print(f"tuple2 is {t2}, tuple2 's type is{type(t2)}")

#-----------如果只有一个元素，那么必须要在后面加上逗号才是元组
t3 = ("feng", )
print(f"tuple3 is {t3}, tuple3 's type is{type(t3)}")

t = (1)
print(f"{t}, {type(t)}")

t1 = ((1,2,3), (4,5,6))
print(f"元组t1为：{t1}, 取出的元素是：{t1[0][2]}")

# -------------------元组的方法
t1 = (1,2,3,4,5,6,7,8,8,9)
index = t1.index(5)
print(f"5的下标是：{index}")
#------------------多重元组不能使用index()
count = t1.count(8)
print(f"在元组t1中有{count}个8")
#------------------.count()方法用于统计某个元素的出现次数
number = len(t1)
print(f"t1中一共有{number}个元素")
#------------------len()函数用于统计所有元素的个数

# while遍历
def while_range(t1):
    index = 0
    while index < len(t1):
        print(f"{t1[index]} ", end = '')
        index += 1

while_range(t1)

#for循环遍历
def for_range(t1):
    for element in t1:
        print(f"{element} ", end = '')

print()
for_range(t1)


# --------在元组中不能修改某个元素的值，但在元组中嵌套一个列表，则可以修改列表的值
t1 = (1, 2, ["feng", "jia", "rui"])

print(f"{t1}")

t1[2][0] = "Feng"
t1[2][1] = "Jia"
t1[2][2] = "Rui"

print(f"{t1}")

